package com.example.baserecyclerviewadapterdemo.activity.multi;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.listener.GridSpanSizeLookup;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.adapter.MultipleItemQuickAdapter;
import com.example.baserecyclerviewadapterdemo.base.BaseActivity;
import com.example.baserecyclerviewadapterdemo.data.DataServer;
import com.example.baserecyclerviewadapterdemo.entity.QuickMultipleEntity;

import java.util.List;

public class MultiItemQuickActivity extends BaseActivity {
    private RecyclerView recyclerView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multiple_item_use);

        getParentToolbar().setTitle("MultipleItemQuick Use");
        getParentToolbar().setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView = findViewById(R.id.rv_list);
        final List<QuickMultipleEntity> data = DataServer.getMultipleItemData();
        final MultipleItemQuickAdapter adapter = new MultipleItemQuickAdapter(data);
        GridLayoutManager manager = new GridLayoutManager(this,4);
        recyclerView.setLayoutManager(manager);
        adapter.setGridSpanSizeLookup(new GridSpanSizeLookup() {
            @Override
            public int getSpanSize(@NonNull GridLayoutManager gridLayoutManager, int viewType, int position) {
                return data.get(position).getSpanSize();
            }
        });
        recyclerView.setAdapter(adapter);

    }

    @Override
    protected boolean hasToolbar() {
        return super.hasToolbar();
    }
}
